import { defineStore } from "pinia";
import { getDefaultGlobalSetting } from "@/entity/setting/GlobalSetting";
import LocalNameEnum from "@/enumeration/LocalNameEnum";

export const useGlobalSettingStore = defineStore("global-setting", () => {
  const globalSetting = useLocalStorage(LocalNameEnum.SETTING_GLOBAL, getDefaultGlobalSetting());

  // getter
  const timeout = computed(() => globalSetting.value.timeout);
  const fontSize = computed(() => globalSetting.value.fontSize || 16);
  const tableHeaderMode = computed(() => globalSetting.value.tableHeaderMode);
  const notificationTime = computed(() => globalSetting.value.notificationTime);
  const homeExcludeIndices = computed(() => globalSetting.value.homeExcludeIndices);
  const homeIncludeIndices = computed(() => globalSetting.value.homeIncludeIndices);
  const pageSize = computed(() => globalSetting.value.pageSize);
  const defaultShard = computed(() => globalSetting.value.defaultShard);
  const defaultReplica = computed(() => globalSetting.value.defaultReplica);

  return {
    globalSetting,
    timeout,
    fontSize,
    tableHeaderMode,
    notificationTime,
    homeExcludeIndices,
    homeIncludeIndices,
    pageSize,
    defaultShard,
    defaultReplica
  };
});
